.SUFFIXES: .tex .rst .pdf

RST2TEX = rst2latex.py
RST2PDFOPTS = --stylesheet-path=/usr/share/pyshared/rst2pdf/styles/ -s twelvepoint.json,serif.json
RST2TEXOPTS = --use-latex-toc --use-latex-citations --stylesheet=../common/mystyle.sty --documentoptions=12
TEX2PDFOPTS =
RUBBEROPTS = --pdf

RERUN = "(There were undefined references|Rerun to get (cross-references|the bars) right|Table widths have changed. Rerun LaTeX.|Linenumber reference failed)"

.rst.tex:
	$(RST2TEX) $(RST2TEXOPTS) $< > $@

.tex.pdf:
	#rubber $(RUBBEROPTS) $< > $(basename $@)
	pdflatex $(TEX2PDFOPTS) $<
	egrep $(RERUN) $*.log && (pdflatex $<) ; true
	egrep $(RERUN) $*.log && (pdflatex $<) ; true

SRCS = functional.rst
PDFS = $(addsuffix .pdf, $(basename $(SRCS)))
TEXS = $(addsuffix .tex, $(basename $(SRCS)))
LOGS = $(addsuffix .log, $(basename $(SRCS)))
AUXS = $(addsuffix .aux, $(basename $(SRCS)))
OUTS = $(addsuffix .out, $(basename $(SRCS)))
TOCS = $(addsuffix .toc, $(basename $(SRCS)))
LOFS = $(addsuffix .lof, $(basename $(SRCS)))
LOTS = $(addsuffix .lot, $(basename $(SRCS)))
DVIS = $(addsuffix .dvi, $(basename $(SRCS)))

all: ${PDFS}
${PDFS}: $(TEXS) ../common/mystyle.sty
${TEXS}: $(SRCS)

clean:
	rm -f $(TEXS)
	rm -f $(LOGS)
	rm -f $(AUXS)
	rm -f $(OUTS)
	rm -f $(TOCS)
	rm -f $(LOFS)
	rm -f $(LOTS)
	rm -f $(DVIS)

realclean: clean
	rm -f $(PDFS)
